package com.zhijian.demo.controller;

import com.zhijian.demo.pojo.Res;
import com.zhijian.demo.pojo.User;
import com.zhijian.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * TODO
 *
 * @author chenzhijian
 * @date 2023/10/17
 */
@RestController
@RequestMapping(value = "/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/addUser", method = RequestMethod.POST)
    public Res addUser(@RequestBody User user){
        return userService.addUser(user);
    }

    @RequestMapping(value = "/deleteUserByUsername", method = RequestMethod.POST)
    public Res deleteUserByUserName(@RequestParam("username") String username){
        return userService.deleteUserByUserName(username);
    }

    @RequestMapping(value = "/updateUserByUsername", method = RequestMethod.POST)
    public Res updateUserByUsername(@RequestParam String oldUsername, @RequestBody User newUser){
        return userService.updateUserByUsername(oldUsername, newUser);
    }

    @RequestMapping(value = "/selectUsers", method = RequestMethod.POST)
    public Res selectUsers(){
        return userService.selectUsers();
    }
}
